﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace Hive.Core.Common.Shell
{
    /// <summary>
    /// Provides interaction with the command shell.
    /// </summary>
    public interface IShell
    {
        /// <summary>
        /// Returns true if the shell has been canceled.
        /// </summary>
        bool IsCanceled { get; }

        /// <summary>
        /// Cancels any commands running in the shell.
        /// </summary>
        void Cancel();

        /// <summary>
        /// The event raised when the shell is canceled.
        /// </summary>
        event EventHandler Canceled;

        /// <summary>
        /// Gets the current directory for resolving relative paths.
        /// </summary>
        DirectoryInfo CurrentDirectory { get; }

        /// <summary>
        /// Gets or sets the shell verbosity.
        /// </summary>
        Verbosity Verbosity { get; set; }

        /// <summary>
        /// Prompts for information from the user.
        /// </summary>
        /// <param name="prompt">The prompt text.</param>
        /// <returns>The user's response.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="prompt"/> is null.</exception>
        string Prompt(string prompt);

        /// <summary>
        /// Writes a message to the console.
        /// </summary>
        /// <param name="severity">The message severity.</param>
        /// <param name="message">The message to write.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> is null.</exception>
        void Echo(MessageSeverity severity, string message);

        /// <summary>
        /// Writes an exception message to the console.
        /// </summary>
        /// <param name="message">The message to display about the exception.</param>
        /// <param name="exception">The exception.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> or <paramref name="exception"/> is null.</exception>
        void EchoException(string message, Exception exception);

        /// <summary>
        /// Executes a process interactively with the shell.
        /// </summary>
        /// <param name="shellCommand">The shell command to execute.</param>
        /// <param name="standardOutputConsumer">The standard output consumer, or null if none.</param>
        /// <param name="standardErrorConsumer">The standard error consumer, or null if none.</param>
        /// <returns>The process exit code.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="shellCommand"/> is null.</exception>
        /// <exception cref="OperationCanceledException">Thrown if the command is cancelable and was canceled.</exception>
        int Execute(ShellCommand shellCommand, StandardOutputConsumer standardOutputConsumer, StandardErrorConsumer standardErrorConsumer);
    }
}
